 class ListNode {
      int val;
      ListNode next;
      ListNode() {}
      ListNode(int val) { this.val = val; }
      ListNode(int val, ListNode next) { this.val = val; this.next = next; }
  }
public class Solution {
    public ListNode swapPairs(ListNode head) {
        if (head == null) {
            return null;
        }
        ListNode dummy_head = new ListNode(0,head);
        ListNode pre = dummy_head;
        ListNode cur = head;
        ListNode curNext = head.next;
        while (cur != null && curNext != null) {
            pre.next = curNext;
            cur.next = curNext.next;
            curNext.next = cur;
            pre = cur;
            cur = cur.next;
            if (cur != null) {
                curNext = cur.next;
            }
        }
        return  dummy_head.next;
    }
}
